#pragma once
#include <iostream>
#include <functional>
#include "InetAddr.hpp"
#include "Epoller.hpp"
#include "Reactor.hpp"
class Reactor;
class Connection;
using connection_t = std::shared_ptr<Connection>;
class Connection
{
public:
    Connection()
    {
    }
    Connection(int sockfd):_sockfd(sockfd)
    {
    }

    ~Connection()
    {

    }
    void SetPeerAddrInfo(InetAddr& peer)
    {
        _peer = peer;
    }
    int Sockfd()
    {
        return _sockfd;
    }
    void SetSockfd(int sockfd)
    {
        _sockfd = sockfd;
    }
    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetOwner(Reactor* owner)
    {
        _owner = owner;
    }
    Reactor* GetOwner()
    {
        return _owner;
    }
    void AppendToOut(const std::string& s)
    {
        _outbuf+=s;
    }
    void Append(const std::string& s)
    {
        _inbuf+=s;
    }
    bool IsOutBufEmpty()
    {
        return _outbuf.empty();
    }
    std::string& InBuf()
    {
        return _inbuf;
    }
    void DisCardOutStr(int n)
    {
        _outbuf.erase(0,n);
    }
    std::string& OutStr()
    {
        return _outbuf;
    }
    virtual void Recv() = 0;
    virtual void Send() = 0;
    virtual void Except() = 0;
protected:
    int _sockfd;
    InetAddr _peer;
    uint32_t _events;//关心的事件


    //
    std::string _inbuf;//输入缓冲区
    std::string _outbuf;//输出缓冲区
    //
    //回调方法
    // func_t _sender;//写
    // func_t _recver;//读
    // func_t _excepter;//处理异常
    //
    Reactor* _owner;
};